﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Cmd
{
    internal class OptionGroupItemEqComparer : IEqualityComparer<OptionGroupItem>
    {
        public bool Equals(OptionGroupItem x, OptionGroupItem y)
        {
            return (x.Option.Command == y.Option.Command ||
                x.Option.Command == y.Option.Alias ||
                x.Option.Alias == y.Option.Command ||
                (x.Option.Alias == y.Option.Alias && !string.IsNullOrWhiteSpace(x.Option.Alias) && !string.IsNullOrWhiteSpace(y.Option.Alias)));
        }

        public int GetHashCode(OptionGroupItem obj)
        {
            return obj.Option.Command.GetHashCode() * (string.IsNullOrWhiteSpace(obj.Option.Alias) ? 1 : obj.Option.Alias.GetHashCode());
        }
    }
}
